<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small" label-width="110px">
            <el-form-item label="审核状态">
              <el-select
                v-model="tableFrom.status" @change.capture="getList(1)"
                placeholder="请选择"
                class="filter-item selWidth"
                clearable
                @change="getList(1)"
              >
                <el-option
                  v-for="item in statusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>

      </div>
      <el-table
          v-loading="listLoading"
          :data="tableData.data"
          style="width: 100%"
          size="small"
      >
        <el-table-column
            label="id"
            prop="id"
            min-width="100" />
        <el-table-column
            label="申请人"
            prop="nickname"
            min-width="100" />
        <el-table-column label="头像" min-width="210">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-if="scope.row.avatar && scope.row.avatar!=1"
                        :src="scope.row.avatar"
                        class="mr5"
                        :preview-src-list="[scope.row.avatar]"
              />
              <el-image v-else
                        src="https://gdw.mage168.com/static/f.png"
                        class="mr5"

              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
            label="业务员"
            prop="ywy_nickname"
            min-width="100" />
        <el-table-column
          label="业务员UID"
          prop="ywy_uid"
          min-width="100" />
        <el-table-column
            label="姓名"
            prop="realname"
            min-width="100" />
        <el-table-column
            label="身份证"
            prop="card"
            min-width="100" />
        <el-table-column
            label="贷款金额"
            prop="loanAmount"
            min-width="100" />

        <el-table-column label="职业资格证" min-width="210" >
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-if="i!=1"
                        v-for="(i,index) in scope.row.business_image"
                        :key="index"
                        :src="i"
                        class="mr5"
                        :preview-src-list="[i]"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
            label="婚姻状态"
            prop="maritalStatus"
            min-width="100" />
        <el-table-column
            label="公积金状态"
            prop="providentFundStatus"
            min-width="100" />
        <el-table-column
            label="学历"
            prop="educationLevel"
            min-width="100" />
        <el-table-column
            label="年收入"
            prop="annualIncome"
            min-width="100" />
        <el-table-column
            label="房产情况"
            prop="assetType"
            min-width="100" />
        <el-table-column
            label="车产情况"
            prop="assetValue"
            min-width="100" />
        <el-table-column
            label="总负债"
            prop="totalliabilities"
            min-width="100" />
        <el-table-column
            label="网贷合计"
            prop="totalonlineloans"
            min-width="100" />
        <el-table-column
            label="持有信用卡"
            prop="xingyoingka"
            min-width="100" />
        <el-table-column label="资格证" min-width="210" v-if="this.tableFrom.type==0||this.tableFrom.type==1">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-if="i!=1"
                        v-for="(i,index) in scope.row.imgArr"
                        :key="index"
                        :src="i"
                        class="mr5"
                        :preview-src-list="[i]"
              />
            </div>
          </template>
        </el-table-column>

        <el-table-column
            prop="createdTime"
            label="申请时间"
            min-width="100"
        />


        <el-table-column
            label="状态"
            min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.status==0">审核中</span>
            <span v-if="scope.row.status==1">审核通过</span>
            <span
                v-if="scope.row.status == 2"
                style="display: block; font-size: 12px; color: red;"
            >驳回，原因 {{ scope.row.fail_msg }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" min-width="100" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="onDetail(scope.row)">详情</el-button>


            <el-button v-if="scope.row.status == 0" type="text" size="small"
                       @click="onAudit(scope.row)">审核</el-button>

          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
            :page-sizes="[20, 40, 60, 80]"
            :page-size="tableFrom.limit"
            :current-page="tableFrom.page"
            layout="total, sizes, prev, pager, next, jumper"
            :total="tableData.total"
            @size-change="handleSizeChange"
            @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--审核-->
    <el-dialog v-if="dialogVisible" :title="isExamine ? '审核' : '详情'" :visible.sync="dialogVisible" width="700px">
      <div v-loading="loading">
        <el-form :model="formData" label-width="100px" ref="formData" :rules="rules">

          <el-form-item label="姓名：" >
            <span>{{formData.realname}}</span>
          </el-form-item>

          <el-form-item label="手机号：" >
            <span>{{formData.phone}}</span>
          </el-form-item>

          <el-form-item label="身份证：" >
            <span>{{formData.card}}</span>
          </el-form-item>
          <el-form-item label="贷款金额：" >
            <span>{{formData.loanAmount}}</span>
          </el-form-item>
          <el-form-item label="婚姻状态：" >
            <span>{{formData.maritalStatus}}</span>
          </el-form-item>
          <el-form-item label="公积金状态：" >
            <span>{{formData.providentFundStatus}}</span>
          </el-form-item>
          <el-form-item label="学历：" >
            <span>{{formData.educationLevel}}</span>
          </el-form-item>
          <el-form-item label="工作单位地址：" >
            <span>{{formData.companyAddress}}</span>
          </el-form-item>
          <el-form-item label="职位：" >
            <span>{{formData.jobTitle}}</span>
          </el-form-item>
          <el-form-item label="行业：" >
            <span>{{formData.jobIndustry}}</span>
          </el-form-item>
          <el-form-item label="工作单位名称：" >
            <span>{{formData.jobCompanyName}}</span>
          </el-form-item>
          <el-form-item label="入职年份：" >
            <span>{{formData.joinYear}}</span>
          </el-form-item>
          <el-form-item label="工作年限：" >
            <span>{{formData.workYear}}</span>
          </el-form-item>
          <el-form-item label="年收入：" >
            <span>{{formData.annualIncome}}</span>
          </el-form-item>
          <el-form-item label="房产情况：" >
            <span>{{formData.assetType}}</span>
          </el-form-item>
          <el-form-item label="车产情况：" >
            <span>{{formData.assetValue}}</span>
          </el-form-item>
          <el-form-item label="总负债：" >
            <span>{{formData.totalliabilities}}</span>
          </el-form-item>
          <el-form-item label="网贷合计：" >
            <span>{{formData.totalonlineloans}}</span>
          </el-form-item>
          <el-form-item label="持有信用卡：" >
            <span>{{formData.xingyoingka}}</span>
          </el-form-item>
          <el-form-item label="资格证：" >
            <div  style="display: inline-block; margin: 0 10px 10px 0">
              <el-image v-for="(i,index) in formData.license" :key="index" style="width: 100px; height: 100px"
                        :src="i" v-if="i!=1"
                        class="mr5"
                        :preview-src-list="[i]"
              />
            </div>
          </el-form-item>
          <el-form-item label="户籍地址：" >
            <span>{{formData.residenceaddress}}</span>
          </el-form-item>
          <el-form-item label="配偶姓名：" >
            <span>{{formData.spouse_realname}}</span>
          </el-form-item>
          <el-form-item label="配偶身份证：" >
            <span>{{formData.spouse_card}}</span>
          </el-form-item>
          <el-form-item label="住宅电话：" >
            <span>{{formData.residence_phone}}</span>
          </el-form-item>
          <el-form-item label="居住状况：" >
            <span>{{formData.live}}</span>
          </el-form-item>

          <el-form-item label="单位性质：" >
            <span>{{formData.unitnature}}</span>
          </el-form-item>
          <el-form-item label="单位电话：" >
            <span>{{formData.unitmobile}}</span>
          </el-form-item>
          <el-form-item label="亲属联系人：" v-if="formData.relatives">
            <div>{{formData.relatives.relatives1}}-{{formData.relatives.relatives2}}-{{formData.relatives.relatives3}}</div>
          </el-form-item>
          <el-form-item label="紧急联系人：" v-if="formData.emergen">
            <div>{{formData.emergen.emergent1}}-{{formData.emergen.emergent2}}-{{formData.emergen.emergent3}}</div>
          </el-form-item>
          <el-form-item label="芝麻分：" >
            <span>{{formData.sesameseed}}</span>
          </el-form-item>
          <el-form-item label="备注：" >
            <span>{{formData.remark}}</span>
          </el-form-item>
          <el-form-item label="注意事项：" >
            <span>{{formData.note}}</span>
          </el-form-item>
          <el-form-item label="业务员：" >
            <span>{{formData.ywy_nickname}}</span>
          </el-form-item>
          <el-form-item label="驳回原因：" v-if="formData.fail_msg">
            <span>{{formData.fail_msg}}</span>
          </el-form-item>
          <el-form-item label="邮箱：" >
            <span>{{formData.email}}</span>
          </el-form-item>
          <el-form-item label="手机号码：" >
            <span>{{formData.phone}}</span>
          </el-form-item>
          <el-form-item label="申请时间：">
            <span>{{formData.createdTime}}</span>
          </el-form-item>
          <el-table-column
              label="状态"
              min-width="100"
          >
            <template slot-scope="scope">
              <span v-if="formData.status==0">审核中</span>
              <span v-if="formData.status==1">审核通过</span>
              <span
                  v-if="formData.status == 2"
                  style="display: block; font-size: 12px; color: red;"
              >驳回，原因 {{ formData.fail_msg }}</span>
            </template>
          </el-table-column>
          <el-form-item v-if="!isExamine && formData.status==1" label="审核通过时间：">
            <span>{{formData.check_time}}</span>
          </el-form-item>
          <el-form-item v-if="isExamine" label="审核状态：" prop="status">
            <el-radio-group v-model="ruleForm.status">
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="-1">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="ruleForm.status===-1 && isExamine" label="原因" prop="msg">
            <el-input v-model="ruleForm.msg" type="textarea" placeholder="请输入原因" />
          </el-form-item>
          <el-form-item v-if="isExamine">
            <el-button type="primary" @click="onSubmit">提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
  examineLanListApi, examinelDetailApi,
  lonlDetailApi,
  lonlshApi
} from '@/api/community'
export default {
  name: 'communityTopic',
  data() {
    return {
      moren: require("@/assets/images/f.png"),
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
      isChecked: false,
      listLoading: true,
      tableData: {
        data: [],
        total: 0
      },
      tableFrom: {
        page: 1,
        is_type:2,
        limit: 20,
        status: "",
        keyword: ""
      },
      statusList: [
        { label: "待审核", value: 0 },
        { label: "审核通过", value: 1 },
        { label: "审核未通过", value: 2 }
      ],
      headeNum: [
        {title: "个人认证", count: 0, type: 0}
      ],
      cateSelect: [],
      topicSelect: [],
      dialogVisible: false,
      loading: false,
      isExamine: false,
      community_id: "",
      formData: {},
      rules: {
        status: [
          { required: true, message: '请选择审核状态', trigger: 'change' }
        ],
        msg: [
          { required: true, message: '请填写拒绝原因', trigger: 'blur' }
        ]
      },
      ruleForm: {
        msg: '',
        status: 1,
      },
    }
  },
  mounted() {
    this.getList(1)

  },
  methods: {
    onDetail(item) {
      this.dialogVisible = true;
      this.community_id = item.id;
      this.isExamine = false;
      lonlDetailApi(this.community_id,{}).then((res) => {
        let formData = res.data
        this.formData = formData
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    },
    // 分类列表；
    getCateSelect() {
      communityCateOptionApi()
          .then((res) => {
            this.cateSelect = res.data;
          })
          .catch((res) => {
            this.$message.error(res.message);
          });
    },
    // 列表
    getList(num) {
      this.listLoading = true
      this.tableFrom.page = num ? num : this.tableFrom.page
      this.tableFrom.type = this.tableFrom.is_type
      examineLanListApi(this.tableFrom).then(res => {
        let list = res.data.list
        this.tableData.data = list

        this.tableData.total = res.data.count
        this.listLoading = false
      }).catch(res => {
        this.listLoading = false
        this.$message.error(res.message)
      })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList('')
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList('')
    },


    // 审核
    onAudit(item) {
      this.community_id = item.id;
      this.dialogVisible = true;
      this.isExamine = true;
      lonlDetailApi(this.community_id,{type:this.tableFrom.type}).then((res) => {
        let formData = res.data


        this.formData = formData
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    },
    onSubmit() {
      this.ruleForm.type = this.tableFrom.type
      lonlshApi(this.community_id,this.ruleForm).then(res => {
        this.$message.success(res.message)
        this.dialogVisible = false
        this.getList('')
      }).catch(res => {
        this.$message.error(res.message)
      })
    },
    // 删除
    handleDelete(id, idx) {
      this.$modalSure('确定删除该文章').then(() => {
        communityDeleteApi(id).then(({ message }) => {
          this.$message.success(message)
          this.getList('')
        }).catch(({ message }) => {
          this.$message.error(message)
        })
      })
    },
    onchangeIsShow(row) {
      communityStatusApi(row.community_id, row.is_show).then(({ message }) => {
        this.$message.success(message)
      }).catch(({ message }) => {
        this.$message.error(message)
      })
    }
  }
}
</script>

<style scoped lang="scss">
.box-container {
  overflow: hidden;
}
.box-container .list {
  float: left;
  line-height: 40px;
}
.box-container .sp {
  width: 50%;
}
.box-container .sp3 {
  width: 33.3333%;
}
.box-container .sp100 {
  width: 100%;
}
.box-container .list .name {
  display: inline-block;
  width: 150px;
  text-align: right;
  color: #606266;
}
.box-container .list.image {
  margin-bottom: 40px;
}
.box-container .list.image img {
  position: relative;
  top: 40px;
}
/deep/.el-form-item__content .el-rate{
  position: relative;
  top: 8px;
}
</style>
